#pragma once

#include "Utils.h"

#include <string>
#include <unordered_map>

// Response instance:
// HTTP/1.1 200 OK
// Access-Control-Allow-Credentials: true
// Access-Control-Allow-Headers: Content-Type,X-Chat-Message,...,ps-dataurlconfigqid,personifiedswitch
// Access-Control-Allow-Methods: GET, POST, DELETE
// Access-Control-Allow-Origin: https://www.baidu.com
// Connection: keep-alive
// Content-Length: 295
// Content-Type: application/json; charset=utf-8
// Date: Fri, 31 Oct 2025 09:05:24 GMT
// Set-Cookie: H_WISE_SIDS=63148_...026 09:05:24 GMT
// Strict-Transport-Security: max-age=2592000
// \n
// {
//     "status": 0,
//     "message": "",
//     "data": {
//         "value": "用AI助手回答：C++",
//         "btn_text": "去AI搜索",
//         "rewrite_query": "C++",
//         "qa_list": [],
//         "default_follow_type": "FOLLOW_CHAT",
//         "qa_list_follow_type": "FOLLOW_CHAT",
//         "req_spec_list": [],
//         "url": "",
//         "is_danger": "0",
//         "is_generate": false
//     },
//     "logid": "10635577660690176479"
// }

/*
HTTP版本 状态码 状态码描述
响应报头
\n
响应正文
*/

class Response {
public:
    Response() : version_("HTTP/1.1"), status_code_("200"), describe_("ok") {}

    void Reset() {
        version_ = "HTTP/1.1";
        status_code_ = "200";
        describe_ = "ok";
        kvs_.clear();
        body_.clear();
    }

    bool HasKey(const std::string& key) { return kvs_.find(key) != kvs_.end(); }

    std::string GetValue(const std::string& key) {
        if (HasKey(key))
            return kvs_[key];
    }

    bool SetValue(const std::string& key, const std::string& value) { kvs_[key] = value; }

    void SetContent(const std::string& body, const std::string& value) {
        body_ = body;
        SetValue("Content-Type", value);
    }

    // 是否为短链接

    std::string Version() { return version_; }
    std::string Describe() { return Utils::GetDescribe(status_code_); }
    std::string Code() { return status_code_; }
    std::string Body() { return body_; }

public:
    std::string version_;
    std::string status_code_;
    std::string describe_;
    std::unordered_map<std::string, std::string> kvs_;
    std::string body_;
};

// int or string